package com.ugoodtech.mdcc.web.controller;

/* Copyright (C) Ugoodtech, Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * Written by Stone Shaw, 15/11/24
 */


import com.ugoodtech.mdcc.web.filter.ValidationCode;
import com.ugoodtech.mdcc.web.dto.JsonResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@ApiIgnore
@Controller
public class PageRedirectController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    @RequestMapping(value = "/welcome", method = RequestMethod.GET)
    public ModelAndView welcome() {
        return new ModelAndView("welcome");
    }

    @RequestMapping(value = "/map", method = RequestMethod.GET)
    public ModelAndView map() {
        return new ModelAndView("map_baidu");
    }

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public ModelAndView login() {
        return new ModelAndView("dashboard_login");
    }

    @RequestMapping(value = "/dealerLogin", method = RequestMethod.GET)
    public ModelAndView dealerLogin() {
        return new ModelAndView("dashboard_dealer_login");
    }

    @RequestMapping(value = "/mapView", method = RequestMethod.GET)
    @ResponseBody
    public ModelAndView mapView() {
        return new ModelAndView("/map_google");
    }

    @PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_SUPER_ADMIN','ROLE_SYSTEM_SUPER_SERVICE')")
    @RequestMapping(value = "/main")
    public String dashMain() {
        logger.debug("enter main!");
        return "dashboard_main";
    }

    @RequestMapping(value = "/dealerMain")
    public String dealerMain() {
        logger.debug("enter dealer main!");
        return "dashboard_dealer_main";
    }


    @PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_CITY_ADMIN')")
    @RequestMapping(value = "/password", method = RequestMethod.GET)
    public ModelAndView password() {
        return new ModelAndView("dashboard_password");
    }

    @RequestMapping("/getValidationCode")
    @ResponseBody
    public void getValidationCode(HttpServletResponse response, HttpServletRequest request) throws Exception {
        ValidationCode code = new ValidationCode();
        code.doGet(request, response);

    }

    /**
     * 获取系统版本
     *
     * @param
     */
    @RequestMapping("/getSystemVersion")
    @ResponseBody
    public JsonResponse getSystemVersion() {
        System.out.print("-------------------getSystemVersion----------------------");
        String version = "1.0.1";
        return JsonResponse.successResponseWithData(version);
    }

    Logger logger = LoggerFactory.getLogger(PageRedirectController.class);
}
